var bankcheck = require('../../utils/bankcheck.js');
// pages/setbank/setbank.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // bankUrl: 'https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?input_charset=utf-8&cardBinCheck=true&cardNo=',阿里线上查API
    time: 60,
    isTimeout: false,
    isTimeDisable: false,
    bankcode: '',
  },
  // 计时器
  settime: function () {
    var that = this;
    var countdown = that.data.time;
    if (countdown == 1) {
      that.setData({
        // 60s走完恢复【获取验证码】+ 可点击
        isTimeout: false,
        isTimeDisable: false,
        time: 60,
      });
    } else {
      that.setData({
        time: countdown - 1,
      });
      setTimeout(function () {
        that.settime()
      }, 1000)
    }
  },
  // 获取验证码
  getCode: function () {
    var that = this;
    that.setData({
      isTimeout: true,
      isTimeDisable: true,
    })
    // 倒计时啦
    that.settime();
  },

  bindBank:function(){
    wx.navigateBack({})
  },

  // 银行名称查询
  checkBank:function(e){
    var that = this;
    var reback = bankcheck.bankCardAttribution(e.detail.value);
    if (reback == 'error'){
      wx.showToast({
        icon: 'none',
        title: '请输入正确的银行卡号',
      });
      that.setData({
        bankcode: ""
      })
    }else{
      that.setData({
        bankcode: reback.bankName
      })
    }
  }
  
})